function [K_mod_reg F_sum_m] = func_Km_R_mod_new(zeta, m, CONSTS, p_m_vec, depend_from_zeta, plot_data)

    a = CONSTS.a;
    k0 = CONSTS.k0;
    c = CONSTS.c;
    d = CONSTS.d;
    eps = CONSTS.eps;
    eps_a = CONSTS.eps_a;
    eta = CONSTS.eta;
    
    Z0 = 4*pi/c;
    
    %p_m_vec = func_p_m(m, CONSTS, span, false);
    %n_beg_sum = n_begining_sum(CONSTS, p_m_vec);
    coef_m_mat = func_coef_m_of_eigenmodes(m, CONSTS, p_m_vec);
    
    if(depend_from_zeta)
        
        diff = zeros(size(zeta), 1);
        K_mn_num = 0; %zeros(size(zeta), 1);
        K_mn_an = 0; %zeros(size(zeta), 1);
        diff_n = 0; %zeros(size(zeta), 1);

        for ii = 1:size(zeta,1)
            zeta_i = zeta(ii);
            for i = 1:size(p_m_vec, 1)
                n = i;
                p_n = p_m_vec(i);
                coef_n = coef_m_mat(:, i);
                norm = func_norm_res(m, CONSTS, coef_n, p_n);
                [~, ~, ~, ~, Ephi, ~] = func_HE_outside(1, m, CONSTS, coef_n, p_n); %func_HE_inside(a, m, CONSTS, coef_n, p_n);

                if(norm==0)
                    K_mn_num = 0;
                else
                    K_mn_num = (2*pi*a/norm)*(Ephi^2)*exp(-1i*k0*p_n*abs(zeta_i));
                    p_an = sqrt(abs(eps/eta))*(2*n+abs(m)+1/2)*(pi/2)*(1/(k0*a));
                    K_mn_an = -Z0*((2*m^2*k0)/(pi*(k0*a)^2))*(sqrt(abs(eps*eta))/...
                               (eps_a^2+abs(eps*eta)))*((exp(-1i*k0*p_an*abs(zeta_i)))/(2*n+abs(m)+1/2));
                end
                diff_n(i) = K_mn_num - K_mn_an;
            end
            
            diff_n(isnan(diff_n))=0;

            diff(ii) = sum(diff_n);
        end
        
        K_mod_reg = diff;
        F_sum_m = sum((abs(m)+3/2)./((2*(1:(size(p_m_vec,1)))+abs(m)+1/2).*(2*(1:(size(p_m_vec,1)))-1)));
            
        if(plot_data)
            figure; plot(zeta./d, real(K_mod_reg), 'b-', zeta./d, imag(K_mod_reg), 'r-');
            title('K_{m, mod} regular part from 0 to inf'); legend('Re(K_m reg)', 'Im(K_m reg)');
            xlabel('\zeta/d');
        end

    else
        
        diff = zeros((size(p_m_vec, 1)), 1);
        K_mn_num = zeros((size(p_m_vec, 1)), 1);
        K_mn_an = zeros((size(p_m_vec, 1)), 1);
        
        for j = 1:size(p_m_vec, 1)
            n = j;
            p_n = p_m_vec(j);
            coef_n = coef_m_mat(:, j);
            norm(j) = func_norm_res(m, CONSTS, coef_n, p_n);
            [~, ~, ~, ~, Ephi(j), ~] = func_HE_outside(1, m, CONSTS, coef_n, p_n);
            if(norm(j)==0)
                K_mn_num(j) = 0;
                K_mn_an(j) = 0;
            else
                K_mn_num(j) = (2*pi*a/norm(j))*(Ephi(j)^2)*exp(-1i*k0*p_n*abs(zeta));
                p_an = sqrt(abs(eps/eta))*(2*n+abs(m)+1/2)*(pi/2)*(1/(k0*a));
                K_mn_an(j) = -Z0*((2*m^2*k0)/(pi*(k0*a)^2))*(sqrt(abs(eps*eta))/(eps_a^2+abs(eps*eta)))*((exp(-1i*k0*p_an*abs(zeta)))/(2*n+abs(m)+1/2));
            end
            diff(j) = K_mn_num(j) - K_mn_an(j);
        end
        
            K_mod_reg_dif = diff;
            K_mod_reg = K_mod_reg_dif;
            
            if(plot_data)
                n_vec = (1:size(p_m_vec, 1))';
                figure; plot(n_vec, real(K_mod_reg_dif), 'k-', n_vec, real(K_mn_num), 'b-', n_vec, real(K_mn_an), 'r-');
                title('real part of K_{m, mod} regular part from 1 to inf'); legend('K_m reg', 'K_m total', 'K_m analyt');
                xlabel('n');
                figure; plot(n_vec, imag(K_mod_reg_dif), 'k-', n_vec, imag(K_mn_num), 'b-', n_vec, imag(K_mn_an), 'r-');
                title('imag part of K_{m, mod} regular part from N to inf'); legend('K_m reg', 'K_m total', 'K_m analyt');
                xlabel('n');
                
%                 figure; plot(n_vec, real(norm), 'b-', n_vec, imag(norm), 'r-');
%                 title('N_{m,n}'); legend('Re(N_{m,n})', 'Im(N_{m,n})'); xlabel('n');
%                 figure; plot(n_vec, real(Ephi.^2), 'b-', n_vec, imag(Ephi.^2), 'r-');
%                 title('E_{\phi;m,n}'); legend('Re(E_{\phi;m,n})', 'Im(E_{\phi;m,n})'); xlabel('n');
            end
    end
    
end

